function classify(type) {
    $.ajax({
        type: 'GET',
        url: `/loader?type=${type}`,
        success: (data) => {
            if (data) {
                createCard(data)
                return;
            } else {
                classify(type);
            }
        }
    })
}

$("#pullBtn").click(function() {
    let roate; //控制箭头的指向
    let box = $(this).parent();
    let state = $(this).attr("name");
    if (state == 'out') {
        box.css({
            "left": "95%",
            backgroundColor: "transparent"
        });
        $(this).attr("name", "in")
        roate = 90;

    } else {
        box.css({
            "left": "0",
            backgroundColor: "rgba(0,0,0,.7)"
        });
        $(this).attr("name", "out")
        roate = -90;
    }
    //点击就清空所有东西。
    setTimeout(() => {
        $("#search_result").html("");
        $("#search_val").val("");
        $("#pullBtn img").css("transform", `rotate(${roate}deg)`);
    }, 1500);
})

$(".type_nav").on('click', (e) => {
    let ev = e || window.event;
    let target = ev.target || ev.srcElement;

    if (target.nodeName.toLocaleLowerCase() == 'li') {
        classify(target.className);
    }
})

$(".search_btn").on("click", search);
$("#search_val").keydown((e) => {
    e = e || window.event
    if (e.keyCode == 13) {
        search()
    }
})

//搜索事件
function search() {
    let str = {};
    let val = $("#search_val").val();

    if (val.indexOf('#') == -1) {
        $.get(
            "/search", { 'name': val },
            function(data) {
                console.log(data)
            }
        )
    } else {
        $.get(
            "/search", { "cx16": val },
            function(data) {
                console.log(data)
            }
        )
    }
}